package com.tianshi.order.mapper;


import com.tianshi.vo.CartVO;
import com.tianshi.entity.CartItems;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartItemMapper {


    @Select("SELECT * FROM cart_items WHERE product_id = #{productId} and cart_id=#{cartId}")
    CartItems getCartItemByProductIdAndCartId(Long productId,Long cartId);

    @Insert("insert into cart_items(cart_id, product_id, quantity, added_at) values(#{cartId}, #{productId}, #{quantity}, #{addedAt})")
    Integer insert(CartItems cartItem);

    Integer update(CartItems cartItem);

    @Select("SELECT product_id as productId,quantity FROM cart_items WHERE cart_id = #{cartId}")
    List<CartVO> getCartList(Long cartId);

    @Delete("delete from cart_items where item_id=#{itemId}")
    Integer delete(Long itemId);


    @Select("SELECT * FROM cart_items WHERE cart_id = #{cartId}")
    List<CartItems> getCartItemByCartId(Long cartId);
}
